<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('客户列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12 search-collapse">
      <form id="role-form">
        <div class="select-list">
          <ul>
            <li>
              公司名称：<input type="text" name="company">
            </li>
            <li>
              客户名称：<input type="text" name="name"/>
            </li>
            <li>
              所属区域：
              <select id="pr">
                <option value="0">请选择</option>
                <option th:each="pr:${prs}" th:value="${pr.getAddress()}" th:text="${pr.getAddress()}"></option>
              </select>
              <select id="city" name="sysCityId">
              </select>
            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
            </li>
          </ul>
        </div>
      </form>
    </div>

    <div class="btn-group-sm" id="toolbar" role="group">
      <a class="btn btn-success" onclick="$.operate.add()">
        <i class="fa fa-plus"></i> 新增
      </a>
      <a class="btn btn-warning" onclick="$.table.exportExcel()">
        <i class="fa fa-download"></i> 导出
      </a>
    </div>

    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table"></table>
    </div>

  </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
  var editFlag = [[${@permission.hasPermi('market:customer:edit')}]];
  var removeFlag = [[${@permission.hasPermi('market:customer:remove')}]];
  var prefix = ctx + "market/customer";


  $(function() {
    var options = {
      url: prefix + "/list",
      createUrl: prefix + "/add",
      detailUrl: prefix + "/detail/{id}",
      updateUrl: prefix + "/edit/{id}",
      removeUrl: prefix + "/remove",
      exportUrl:prefix + "/export",
      modalName: "客户",
      columns: [{
        checkbox: true
      },
        {
          field: 'id',
          title: '序号'
        },
        {
          field: 'name',
          title: '客户姓名',
        },
        {
          field: 'sex',
          title: '性别',
        },
        {
          field: 'telephone',
          title: '联系电话',
        },
        {
          field: 'company',
          title: '所属公司',
        },
        {
          field: 'sysCityId',
          title: '所属区域',
        },
        {
          field: 'status',
          title: '状态',
          formatter: function (value) {
            if (value == 0) {
              return '不可用'
            }else {
              return '可用'
            }
          }
        },
        {
          field: 'createTime',
          title: '创建时间',
        },
        {
          field: 'sysCreateUserId',
          title: '创建人',
        },
        {
          field: 'cityname',
          title: '所属城市',
        },
        {
          field: 'createby',
          title: '创建人名称',
        },
        {
          title: '操作',
          align: 'center',
          formatter: function(value, row, index) {
            if (row.wareId != 0) {
              var action = [];

              if (row.repoStatus == 0) {
                action.push('<a class="btn btn-primary btn-sm" href="#">恢复</a>');
              }else {
                action.push('<a class="btn btn-success btn-sm" href="#" style="margin-right: 5px" onclick="$.operate.detail('+ row.wareId +')">查看详情</a>');
                action.push('<a class="btn btn-warning btn-sm" href="#" style="margin-right: 5px;" onclick="$.operate.edit('+ row.wareId +')">修改</a>');
                action.push('<a class="btn btn-danger btn-sm" href="#" style="margin-right: 5px;" onclick="$.operate.remove('+ row.id +')">撤销</a>')
              }
              return action.join('');
            } else {
              return "";
            }
          }
        }]
    };
    $.table.init(options);
  });

  $("#pr").change(function () {
    $.get("/storage/ware/city/" + $("#pr").val(),{},function (data) {
      let options = '';
      for (let i = 0; i < data.length; i++) {
        options += '<option value="'+ data[i].cityId +'">'+ data[i].cityName +'</option>'
      }

      $("#city").html(options);
    })
  })
</script>
</body>
</html>